# -*- coding:utf-8 -*-
# https://wangzhangfei.blog.csdn.net/article/details/108952628
# author: wangfeng
# create date: 2022-08-25 13:53:32
#

import os
import sys
import logging
import time

__VERSION__ = '1.0.1'


class pylog(object):
    """logger class"""

    def __init__(self, log_path: str):
        self.__log_path = log_path
        self.__logger = logging.getLogger()
        self.__logger.setLevel(logging.INFO)  # log 总等级

        logfile = self.__log_path
        fh = logging.FileHandler(logfile, mode='a')
        # fh.setLevel(logging.DEBUG)
        # fh.setLevel(logging.INFO)

        ch = logging.StreamHandler()
        ch.setLevel(logging.WARNING)

        formatter = logging.Formatter("%(asctime)s - %(filename)s[line:%(lineno)d] - %(levelname)s:%(message)s")

        fh.setFormatter(formatter)
        ch.setFormatter(formatter)

        self.__logger.addHandler(fh)
        self.__logger.addHandler(ch)

        pass

    def write_info_log(self, msg: str):
        """get"""
        # self.__logger.debug(str)
        self.__logger.info(msg)
        # logger2.warning('这是 {0}'.format('warning'))
        # logger2.error('这是 {0}'.format('error'))
        # logger2.critical('这是 {0}'.format('critical'))

    def write_warning_log(self, msg: str):
        self.__logger.warning(msg)

    @staticmethod
    def get_log_base_name():
        """date.log"""
        ret = time.gmtime()
        ret = time.strftime("%Y%m%d.log", ret)
        return ret


if __name__ == "__main__":
    """demo"""
    print("get log:")
    def_file_name = '2.txt'

    if len(sys.argv) <= 1:
        print("get log: error !")
        pass
    else:
        # write_log(sys.argv[1])
        def_file_name = sys.argv[1]
        pass
